<template>
    <div class="login-wrap">
        <div class="bold-title">
            江 西 省 水 土 保 持 综 合 管 理 平 台
        </div>
        <div id="allmap">

        </div>
        <div class="ms-login">
            <div class="left" id="echarts">
                
            </div>
            <div class="right">
                <div class="ms-title">登录</div>
                <el-form :model="param" :rules="rules" ref="login" label-width="0px" class="ms-content">
                    <el-form-item prop="username">
                        <el-input v-model="param.username" placeholder="账号">
                            <el-button slot="prepend" icon="el-icon-lx-people"></el-button>
                        </el-input>
                    </el-form-item>
                    <el-form-item prop="password">
                        <el-input
                            type="password"
                            placeholder="密码"
                            v-model="param.password"
                            @keyup.enter.native="submitForm()"
                        >
                            <el-button slot="prepend" icon="el-icon-lx-lock"></el-button>
                        </el-input>
                    </el-form-item>
                    <div class="login-btn">
                        <el-button type="primary" @click="submitForm()">登录</el-button>
                    </div>
                    <el-checkbox v-model="remPwd">记住密码</el-checkbox>
                    <p class="login-tips tip-icon">
                        
                        本系统建议您使用1280*800及以上分辨率的屏幕</p>
                    <p class="login-tips">推荐浏览器：chrome、360极速、IE10以上</p>
                </el-form>
            </div>
        </div>
    </div>
</template>

<script>

//const echarts = require("echarts")
import { Base64 } from 'js-base64';
export default {
    data: function() {
        return {
       
            remPwd:true,
            initOption:{
               tooltip: {
                    trigger: 'item',
                    formatter: function(val){
                        var data=val.value?val.value:0
                        return val.name+':'+data
                        
                    }
                },
                grid: {
                    left:'2%',
                    top: '2%',
                    right: '2%',
                    bottom:'2%'
                },

                geo:{
                    type:'map',
                    map:'shengMap',
                    label: {  
                            normal: {  
                                show: true  //省份名称  
                            },  
                            emphasis: {  
                                show: true  
                            }  
                        }
                }
            },
            param: {
                username: '',
                password: '',
            },
            myChart:null,
            rules: {
                username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
                password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
            },
        };
    },
    created(){
        let pwd=localStorage.getItem('pwd')
        if(pwd){
            console.log(Base64.decode(pwd))
        } 
    },
    mounted(){
        for (var i =0;i<jiangxiJSON.features.length;i++) {
            jiangxiJSON.features[i].properties.name = jiangxiJSON.features[i].properties.name.replace(/市/i,'')
        }      
        // let map = new BMapGL.Map('allmap');
        // map.centerAndZoom(new BMapGL.Point(116.404, 39.915), 12);
        // map.enableScrollWheelZoom(true);
        // map.setMapType(BMAP_EARTH_MAP);
        // map.setDisplayOptions({
        //     poiText: false
        // })
        // map.setDisplayOptions({
        //     building: false
        // })
        // map.setDisplayOptions({
        //     poiIcon: false
        // })
        // map.setDisplayOptions({
        //     street: false
        // })
        echarts.registerMap('shengMap',jiangxiJSON)
        this.myChart= echarts.init(document.getElementById('echarts'));
        this.myChart.setOption(this.initOption)
    },
    methods: {
        submitForm() {
            let that=this
            this.$refs.login.validate(valid => {
                if (valid) {
                    if(that.remPwd){
                        localStorage.setItem("pwd",Base64.encode(that.param.password))
                    }else{
                        localStorage.removeItem("pwd")
                    }
                    this.$message.success('登录成功');
                    localStorage.setItem('ms_username', this.param.username);
                    sessionStorage.setItem('token',111)
                    this.$router.push('/');
                } else {
                    this.$message.error('请输入账号和密码');
                    console.log('error submit!!');
                    return false;
                }
            });
        },
    },
};
</script>

<style scoped>
.tip-icon{
    background:url(../../assets/img/info.png) no-repeat 0px 6px;
    background-size:16px 16px;
}
.bold-title{
    text-align:center;
    font-size:32px;
    font-weight:bold;
    color:#fff;
    position:absolute;
    top:20%;
    left:0;
    right:0;
}
#allmap{
    height:100%;
}
.login-wrap {
    position: relative;
    width: 100%;
    height: 100%;
    background:url(../../assets/img/login.jpg) no-repeat;
    background-size: 100% 100%;
}
.ms-title {
    width: 100%;
    line-height: 50px;
    text-align: center;
    font-size: 20px;
    
    border-bottom: 1px solid #ddd;
}
.ms-login {
    position: absolute;
    left: 50%;
    z-index:10000;
    top: 50%;
    width: 700px;
    margin: -190px 0 0 -350px;
    border-radius: 5px;
    background: rgba(255, 255, 255, 1);
    overflow: hidden;
    display:flex;
}
.ms-login .left{
    width:350px;
    height:317px;
    border-right:1px solid #ccc;
}
.ms-login .right{
    width:350px;
}
.ms-content {
    padding: 30px 30px;
}
.login-btn {
    text-align: center;
}
.login-btn button {
    width: 100%;
    height: 36px;
    margin-bottom: 10px;
}
.login-tips {
    padding-left:20px;
    font-size: 12px;
    line-height: 30px;
    color: #333;
}
</style>